package org.blueoxygen.rest.geneology.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.blueoxygen.cimande.CimandeAction;
import org.blueoxygen.rest.geneology.Person;

import com.opensymphony.xwork2.ModelDriven;

@Action("child")
public class PersonsChildController extends CimandeAction implements ModelDriven<Object>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected List<Person> childs = new ArrayList<Person>();
	public String show() {
		Person p = (Person) session.get(Person.class, id);
		String hql = "FROM " + Person.class.getName() + "";
		if (p.isMale()) {
			hql += " WHERE father.id = '" + p.getId() + "'";
		} else {
			hql += " WHERE mother.id = '" + p.getId() + "'";
		}
		childs = session.createQuery(hql).list();
		System.out.println(hql);
		return "android/android-login";
	}

	public Object getModel() {
		return childs;
	}
}
